//
//  GoodsCollectionViewCell2.m
//  UGoods
//
//  Created by dllo on 16/1/17.
//  Copyright © 2016年 蓝鸥科技.李贺. All rights reserved.
//

#import "GoodsCollectionViewCell2.h"
#import "FindModel.h"
#import "BaseLabel.h"
#import <UIImageView+WebCache.h>
#import "ConstantsDefine.h"
@interface GoodsCollectionViewCell2 ()

@property (nonatomic, retain) UIImageView *goodsImageView;
@property (nonatomic, retain) BaseLabel *goodsNameLabel;
@property (nonatomic, retain) BaseLabel *priceLabel;
@property (nonatomic, retain) UILabel *timeLabel;

@end

@implementation GoodsCollectionViewCell2
- (void)dealloc
{
    [_goodsImageView release];
    [_goodsNameLabel release];
    [_priceLabel release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.goodsImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_goodsImageView];
        [_goodsNameLabel release];
        
//        self.timeLabel = [[UILabel alloc] init];
//        self.timeLabel.textAlignment = NSTextAlignmentCenter;
//        _timeLabel.font = [UIFont systemFontOfSize:12];
//        _timeLabel.textColor = [UIColor whiteColor];
//        _timeLabel.backgroundColor = [UIColor colorWithRed:1.000 green:0.600 blue:0.600 alpha:0.800];
//        [_goodsImageView addSubview:_timeLabel];
//        [_timeLabel release];
        
        self.goodsNameLabel = [[BaseLabel alloc] init];
        //        _goodsNameLabel.textAlignment = NSTextAlignmentCenter;
//                _goodsNameLabel.backgroundColor = [UIColor greenColor];
        _goodsNameLabel.numberOfLines = 2;
        _goodsNameLabel.font = [UIFont systemFontOfSize:12 * WIDTH];
        [self.contentView addSubview:_goodsNameLabel];
        [_goodsNameLabel release];
        
        self.priceLabel = [[BaseLabel alloc] init];
//                _priceLabel.backgroundColor = [UIColor yellowColor];
        _priceLabel.font = [UIFont systemFontOfSize:12 * WIDTH];
        _priceLabel.textColor = [UIColor redColor];
        [self.contentView addSubview:_priceLabel];
        [_priceLabel release];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    _goodsImageView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, 140 * HEIGHT);
    
//    if (_timeLabel.text.length != 0) {
//        _timeLabel.frame = CGRectMake(0, self.goodsImageView.frame.size.height - 20, self.goodsImageView.frame.size.width, 20);
//    } else {
//        return;
//    }
    
    _goodsNameLabel.frame = CGRectMake(0, 150 * HEIGHT, self.contentView.frame.size.width - 30 * WIDTH, 20 * HEIGHT);
    _priceLabel.frame = CGRectMake(self.contentView.frame.size.width - 30 * WIDTH, 150 * HEIGHT, 40 * WIDTH, 20 * HEIGHT);
}

- (void)setModel:(FindModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [_goodsImageView sd_setImageWithURL:[NSURL URLWithString:model.list_url] placeholderImage:[UIImage imageNamed:@"place2"]];
    
//    NSString *str = model.end_time;
//    NSTimeInterval time=[str doubleValue]+28800;//因为时差问题要加8小时 == 28800 sec
//    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
//    //    NSLog(@"date:%@",[detaildate description]);
//    //实例化一个NSDateFormatter对象
//    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//    //设定时间格式,这里可以设置成自己需要的格式
//    [dateFormatter setDateFormat:@"d天mm时ss分"];
//    NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
//    _timeLabel.text = [NSString stringWithFormat:@"剩余时间 %@", currentDateStr];
    
    if (model.goods_name.length != 0) {
        _goodsNameLabel.text = model.goods_name;
    } else if (model.title != 0) {
        _goodsNameLabel.text = model.title;
    }
    
    
    _priceLabel.text = [NSString stringWithFormat:@"¥%@", model.shop_price];

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
